package br.unb.graphics.actions;

import br.unb.graphics.GraphicInterface;
import br.unb.graphics.inference.InferenceDataImporter;
import br.unb.utils.Console;
import br.unb.utils.LogFile;
import br.unb.utils.Path;
import br.unb.utils.Resource;
import java.awt.event.ActionEvent;
import java.io.File;
import javax.swing.AbstractAction;
import javax.swing.JFileChooser;

/**
 *
 * @author spider
 */
public class OpenInferenceAction extends AbstractAction {

    public static final String openInferenceAction = "openInference";

    public OpenInferenceAction() {
        super(openInferenceAction);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        //TODO review open file action (too clumbersome)
        JFileChooser fc = new JFileChooser(Path.getLogDir());
        fc.setFileFilter(LogFile.Type.RECEIVER.getFileFilter());
        fc.setDialogTitle("Open Inference File");

        int o = fc.showOpenDialog(null);
        switch (o) {
            case JFileChooser.APPROVE_OPTION: {
                File inferencefile = (File) fc.getSelectedFile();
                if (inferencefile != null) {
                    InferenceDataImporter dataimporter = new InferenceDataImporter(inferencefile);
                    dataimporter.setSize(InferenceDataImporter.firstPaneDimension);
                    dataimporter.setResizable(false);
                    dataimporter.setVisible(true);
                    GraphicInterface.getInstance().showInferencePanel();
                } else {
                    Console.printError(Resource.getString("SELECT_VALID_FILE"));
                }
            }
            break;
            case JFileChooser.CANCEL_OPTION: {
                Console.printError(Resource.getString("FILE_SELECTION_CANCELED"));
            }
            break;
        }
    }
}
